//
//  BudgetRule.m
//  
//
//  Created by barak on 10/26/12.
//  Copyright (c) 2012 yaniv. All rights reserved.
//

#import "BudgetRule.h"

@implementation BudgetRule

@synthesize category;
@synthesize budgetLimit;
@synthesize utilization;
@synthesize budgetId;

+ (BudgetRule *)instanceFromDictionary:(NSDictionary *)aDictionary {

    BudgetRule *instance = [[BudgetRule alloc] init];
    [instance setAttributesFromDictionary:aDictionary];
    return instance;

}

- (void)setAttributesFromDictionary:(NSDictionary *)aDictionary {

    if (![aDictionary isKindOfClass:[NSDictionary class]]) {
        return;
    }

    [self setValuesForKeysWithDictionary:aDictionary];

}

- (NSDictionary *)dictionaryRepresentation {

    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

    if (self.category) {
        [dictionary setObject:self.category forKey:@"category"];
    }

    if (self.budgetLimit) {
        [dictionary setObject:self.budgetLimit forKey:@"budget_limit"];
    }

    if (self.utilization) {
        [dictionary setObject:self.utilization forKey:@"utilization"];
    }

    return dictionary;

}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
    if ([key isEqualToString:@"budget_limit"]) {
        [self setValue:value forKey:@"budgetLimit"];
    } else if ([key isEqualToString:@"budget_id"]){
        [self setValue:value forKey:@"budgetId"];
    }
    
}


@end
